<template>
  <el-form ref="form" :rules="rules" label-width="100px">
    <el-form-item label="步骤名称" prop="name">
      <el-input v-model="step.name" placeholder="步骤名称"></el-input>
    </el-form-item>
    <el-form-item label="执行次数">
      <el-input-number v-model="step.limit" placeholder="执行次数" :min="1"></el-input-number>
    </el-form-item>
    <br>
    <el-button icon="plus" @click="_addRecord"></el-button>
    <br><br>
    <el-table :data="step.fields" stripe border :max-height="300">
      <el-table-column type="index" :width="60"></el-table-column>
      <el-table-column label="名称" :width="100">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.name}}</div>
          <el-input v-else v-model="scope.row.name" size="mini"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="类型" :width="120">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.type}}</div>
          <el-select v-else v-model="scope.row.type" size="mini">
            <el-option v-for="item in options.inputTypes" :value="item"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="值" :width="120">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.nullif}}</div>
          <el-input v-else v-model="scope.row.nullif" size="mini"></el-input>
        </template>
      </el-table-column>
      <el-table-column label="设为空" :width="100">
        <template scope="scope">
          <div v-if="!scope.row.edit">{{scope.row.set_empty_string}}</div>
          <el-select v-else v-model="scope.row.set_empty_string" size="mini">
            <el-option label="是" value="Y"></el-option>
            <el-option label="否" value="N"></el-option>
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="控制" :width="120">
        <template scope="scope">
          <el-row>
            <el-col :span="12"><el-button size="mini" type="info" @click="reverseEditState(scope.$index, scope.row)">编辑</el-button>
            </el-col>
            <el-col :span="12">
              <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </el-col>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
  </el-form>
</template>
<style>

</style>
<script>
  import {Steps, Fields,Options} from "../../model/DataModel";
  import StepCommon from "./mixins/StepMixin";

  /**
   * 生成记录step 输出fields.name
   * */
  export default{
    mixins: [StepCommon],
    data(){
      return {
        step: Steps.RowGenerator(),
        options:Options
      }
    },
    methods:{
      updateFields(){
        this.step.outputFields=this.step.fields.map(el=>el.name);
      }
    }
  }
</script>
